package com.foreveross.pushsdk.core;

 

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

/**
 * @author Huang Li
 * @version 创建时间：2014年5月19日 下午2:17:09
 * UserId，用来区分不同用户或者群体，已确定推送的目标。
 */
public class PushPreferences {

	private  SharedPreferences preference;
	private String currentUser;
	
	public PushPreferences(Context context,String userId) {
		preference = PreferenceManager.getDefaultSharedPreferences(context); 
		String uString=userId;
		if(uString==null||uString.equals("")){
			uString="guest";
		}
		currentUser=uString;
	}
	public void saveToken(String token){
		Editor editor = preference.edit();
        editor.putString(PushConstants.PUSH_TOKEN+currentUser, token);
        editor.commit();
	}
	public String getToken(){
		return preference.getString(PushConstants.PUSH_TOKEN+currentUser, "");
	}
	public int getExpiedTime() {
		return preference.getInt(PushConstants.EXPIRED_TIME+currentUser, 0);
	}
	public void saveExpiredTime(int time){
		Editor editor = preference.edit();
        editor.putInt(PushConstants.EXPIRED_TIME+currentUser,time);
        editor.commit();
	}
	public void saveTokenCreateTime(String time){
		Editor editor = preference.edit();
        editor.putString(PushConstants.TOKEN_CREATE_TIME+currentUser,time);
        editor.commit();	
	}
	public String getTokenCreateTime(){
		return preference.getString(PushConstants.TOKEN_CREATE_TIME+currentUser, "");
	}
	
	public int getTempPort() {
		return preference.getInt(PushConstants.TEMP_PORT+currentUser, 0);
	}
	public void saveTempPort(int port){
		Editor editor = preference.edit();
        editor.putInt(PushConstants.TEMP_PORT+currentUser,port);
        editor.commit();
	}
	public void saveTempHost(String host){
		Editor editor = preference.edit();
        editor.putString(PushConstants.TEMP_HOST+currentUser,host);
        editor.commit();	
	}
	public String getTempHost(){
		return preference.getString(PushConstants.TEMP_HOST+currentUser, "");
	}
	
}
